package org.chabad.android;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.RadioButton;

public class Prefrences extends Activity {
	RadioButton rdoZip;
	EditText txtZip;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.prefrences);
        
        rdoZip  = (RadioButton)findViewById(R.id.rdoZip);
        txtZip  = (EditText)findViewById(R.id.txtZip);
        
        rdoZip.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				txtZip.setEnabled(isChecked);
				
			}
		});
        SharedPreferences prefs = getSharedPreferences("Chabad.org", MODE_PRIVATE);
        String zip = prefs.getString("ZipOverride", null);
        
        if(zip != null)
        {
        	rdoZip.setChecked(true);
        	txtZip.setText(zip);
        }
	}
	
	@Override
	protected void onPause() {
		super.onPause();
        SharedPreferences prefs = getSharedPreferences("Chabad.org", MODE_PRIVATE);
        Editor edit = prefs.edit();
		if(rdoZip.isChecked())
		{
			edit.putString("ZipOverride", txtZip.getText().toString());
		}else{
			edit.remove("ZipOverride");
		}
		edit.commit();
	}
}
